<template>
  <div class="dashboard-container">
    <!-- 原有待办事项卡片 -->
    <el-card class="todo-container">
      <div slot="header" class="card-header">
        <div class="header-content">
          <i class="el-icon-bell header-icon"></i>
          <span class="header-title">待办事项</span>
          <span class="todo-count">
            {{ filteredTodos.length }} 
            {{ currentTab === 'processing' ? '条待处理' : '条事项' }}
          </span>
        </div>
      </div>
      <div class="tab-bar">
        <span class="tab-item" :class="{ active: currentTab === 'all' }" @click="currentTab = 'all'">全部</span>
        <span class="tab-item" :class="{ active: currentTab === 'processing' }" @click="currentTab = 'processing'">待处理</span>
        <span class="tab-item" :class="{ active: currentTab === 'processed' }" @click="currentTab = 'processed'">已处理</span>
      </div>
      <ul class="todo-list">
        <li v-for="(item, index) in filteredTodos" :key="index" class="todo-item">
          <span class="status-tag" :class="item.status === 'processing' ? 'processing' : 'processed'">
            [{{ item.status === 'processing' ? '待处理' : '已处理' }}]
          </span>
          <span class="content">{{ item.content }}</span>
          <span v-if="item.status === 'processing'" class="handle-btn">去处理</span>
          <span v-else class="handle-btn">查看详细</span>
          <span class="time">{{ item.time }}</span>
        </li>
      </ul>
    </el-card>

    <!-- 新增合作通知卡片 -->
    <el-card class="todo-container">
      <div slot="header" class="card-header">
        <div class="header-content">
          <i class="el-icon-chat-dot-square header-icon"></i>
          <span class="header-title">合作通知</span>
          <span class="todo-count">
            {{ filteredNotifications.length }} 
            {{ notificationTab === 'unread' ? '条未读' : (notificationTab === 'read' ? '条已读' : '条通知') }}
          </span>
        </div>
      </div>
      <div class="tab-bar">
        <span class="tab-item" :class="{ active: notificationTab === 'all' }" @click="notificationTab = 'all'">全部</span>
        <span class="tab-item" :class="{ active: notificationTab === 'read' }" @click="notificationTab = 'read'">已读</span>
        <span class="tab-item" :class="{ active: notificationTab === 'unread' }" @click="notificationTab = 'unread'">未读</span>
      </div>
      <ul class="todo-list">
        <li v-for="(item, index) in filteredNotifications" :key="index" class="todo-item">
          <span class="status-tag" :class="item.status === 'unread' ? 'unread' : 'read'">
            [{{ item.status === 'unread' ? '未读' : '已读' }}]
          </span>
          <span class="content">{{ item.content }}</span>
          <span v-if="item.status === 'unread'" class="handle-btn">标记为已读</span>
          <span v-else class="handle-btn">查看详情</span>
          <span class="time">{{ item.time }}</span>
        </li>
      </ul>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      currentTab: 'all',
      todos: [
        { status: 'processing', content: '成员【数据提供商二】邀请您加入项目【MNIST数据分类】', time: '2025-03-14 15:00' },
        { status: 'processed', content: '成员【发起方】邀请您加入项目【1123】', time: '2025-03-27 21:48:10' },
        { status: 'processing', content: '请审核成员【数据提供商二】加入项目【分类测试项目】的请求', time: '2024-11-26' }
      ],
      notificationTab: 'all',
      notifications: [
        { status: 'unread', content: '【ABC公司】邀请您参与联合项目', time: '2025-03-29 10:00' },
        { status: 'read', content: '【XYZ集团】确认合作条款', time: '2025-03-28 15:30' },
        { status: 'unread', content: '【123科技】请求查看项目资料', time: '2025-03-27 09:45' }
      ]
    };
  },
  computed: {
    filteredTodos() {
      if (this.currentTab === 'all') return this.todos;
      if (this.currentTab === 'processing')
        return this.todos.filter(item => item.status === 'processing');
      return this.todos.filter(item => item.status === 'processed');
    },
    filteredNotifications() {
      if (this.notificationTab === 'all') return this.notifications;
      if (this.notificationTab === 'unread')
        return this.notifications.filter(item => item.status === 'unread');
      return this.notifications.filter(item => item.status === 'read');
    }
  }
};
</script>

<style scoped>
/* 滚动条样式 */
.todo-list {
  list-style: none;
  padding: 0;
  max-height: calc(100vh - 10px); /* 根据视口高度调整 */
  /* 固定列表高度 */
  overflow-y: auto;
  /* 垂直滚动条 */
  margin: 0 -12px;
  /* 抵消内边距 */
}

.todo-item {
  margin-bottom: 10px;
  padding: 8px;
  background: white;
  border-radius: 4px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.status-tag {
  padding: 2px 8px;
  border-radius: 4px;
  flex-shrink: 0;
  width: 70px;
  text-align: center;
}

.content {
  flex: 1;
  min-width: 0;
  line-height: 1.5;
  padding-right: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}

.handle-btn {
  color: #409eff;
  cursor: pointer;
  flex-shrink: 0;
  margin-left: auto;
}

.time {
  color: #999;
  font-size: 12px;
  flex-shrink: 0;
  width: 140px;
  text-align: right;
}

/* 其他原有样式保留 */
.todo-container {
  flex-basis: 50%; /* 各占50%宽度 */
  box-sizing: border-box; /* 包含padding计算宽度 */
  min-width: 300px; /* 防止过小屏幕内容溢出 */
  max-height: calc(100vh - 10px); /* 根据视口高度调整 */
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
  border: none;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.todo-container:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

.tab-bar {
  margin-bottom: 20px;
}

.tab-item {
  display: inline-block;
  padding: 8px 16px;
  margin-right: 10px;
  cursor: pointer;
  border-radius: 4px;
}

.tab-item.active {
  background: #409eff;
  color: white;
}

.processing {
  background: #fff9db;
  color: #f5a623;
}

.processed {
  background: #e8f6e8;
  color: #67c23a;
}

.card-header {
  background: linear-gradient(135deg, #f8f9fa 0%, #f1f3f5 100%);
  border-bottom: 1px solid #e9ecef !important;
  padding: 5px 5px !important;
}

.header-content {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-icon {
  font-size: 20px;
  color: #409EFF;
  padding: 8px;
  background: rgba(64, 158, 255, 0.1);
  border-radius: 8px;
}

.header-title {
  font-size: 18px;
  font-weight: 600;
  color: #2c3e50;
  letter-spacing: 0.5px;
}

.todo-count {
  margin-left: auto;
  font-size: 14px;
  color: #6c757d;
  background: rgba(108, 117, 125, 0.08);
  padding: 4px 10px;
  border-radius: 12px;
}

.status-tag.unread {
  background: #fff9db;
  color: #f5a623;
}

.status-tag.read {
  background: #e8f6e8;
  color: #67c23a;
}

/* 合作通知图标样式 */
.el-icon-chat-dot-square {
  color: #2563eb;
  background: rgba(37, 99, 235, 0.1);
}

/* 布局调整 */
.dashboard-container {
  display: flex;
  flex-direction: row;
  gap: 20px;
  padding: 20px;
  flex-wrap: nowrap; /* 禁止换行 */
}

</style>